<script setup lang="ts">
import { onMounted } from "vue";
import { useMenuStore } from "@/stores/menu";
import type { Menu } from "@/business/entity/menu.entity";
import router from "@/router";
const menusStore = useMenuStore();

onMounted(() => {
  const routerName: any = router.currentRoute.value.name;
  const el = document.querySelector(".tarot-menu-" + routerName);
  const activeEl = document.querySelector(".active");
  activeEl?.classList.remove("active");
  el?.classList.add("active");
});

const clickParentBtn = async (menu: Menu) => {
  router.push({ name: menu.name });
};
</script>

<template>
  <div id="dashboard">
    <el-row :gutter="20">
      <el-col :span="8" v-for="(nav, key) in menusStore.menus" :key="key" @click="clickParentBtn(nav as Menu)" >
        <div class="grid-content ep-bg-purple">
          <el-icon class="tarot-icon"><component :is="nav.icon" /></el-icon
          >{{ nav.menuName }}
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<style lang="scss" scoped>
#dashboard {
  padding: 20px;
  .grid-content {
    border-radius: 4px;
    min-height: 200px;
  }
  .ep-bg-purple {
    background: #e7e8ea;
    font-size: 26px;
    color: #328bef;
    text-align: center;
    line-height: 200px;
    vertical-align: center;
    &:hover {
      background: #5c8ef1;
      cursor: pointer;
      color: white;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    }
  }
  .tarot-icon {
    position: relative;
    top: 13px;
    font-size: 50px;
  }
}
</style>
